home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / H145.ZIP / ASXXXX_3.ZIP / M04ADR.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  2KB  |  125 lines

  1. /* m04adr.c */
  2.  
  3. /*
  4.  * (C) Copyright 1989,1990
  5.  * All Rights Reserved
  6.  *
  7.  * Alan R. Baldwin
  8.  * 721 Berkeley St.
  9.  * Kent, Ohio  44240
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <setjmp.h>
  14. #include "asm.h"
  15. #include "m6804.h"
  16.  
  17. int
  18. addr(esp)
  19. register struct expr *esp;
  20. {
  21.     register c;
  22.     register struct area *espa;
  23.  
  24.     if ((c = getnb()) == '#') {
  25.         expr(esp, 0);
  26.         esp->e_mode = S_IMMED;
  27.     } else if (c == ',') {
  28.         if ((esp->e_mode = admode(xy)) == 0)
  29.             aerr();
  30.         esp->e_flag = 0;
  31.         esp->e_addr = 0;
  32.         esp->e_base.e_ap = NULL;
  33.     } else {
  34.         unget(c);
  35.         expr(esp, 0);
  36.         esp->e_mode = S_DIR;
  37.     }
  38.     if (esp->e_addr & ~0xFF)
  39.         aerr();
  40.     return (esp->e_mode);
  41. }
  42.     
  43. /*
  44.  * Enter admode() to search a specific addressing mode table
  45.  * for a match. Return the addressing value on a match or
  46.  * zero for no match.
  47.  */
  48. int
  49. admode(sp)
  50. register struct adsym *sp;
  51. {
  52.     register char *ptr;
  53.     register int i;
  54.     unget(getnb());
  55.     i = 0;
  56.     while ( *(ptr = (char *) &sp[i]) ) {
  57.         if (srch(ptr)) {
  58.             return(sp[i].a_val);
  59.         }
  60.         i++;
  61.     }
  62.     return(0);
  63. }
  64.  
  65. /*
  66.  *      srch --- does string match ?
  67.  */
  68. int
  69. srch(str)
  70. register char *str;
  71. {
  72.     register char *ptr;
  73.     ptr = ip;
  74.  
  75. #if    CASE_SENSITIVE
  76.     while (*ptr && *str) {
  77.         if(*ptr != *str)
  78.             break;
  79.         ptr++;
  80.         str++;
  81.     }
  82.     if (*ptr == *str) {
  83.         ip = ptr;
  84.         return(1);
  85.     }
  86. #else
  87.     while (*ptr && *str) {
  88.         if(ccase[*ptr] != ccase[*str])
  89.             break;
  90.         ptr++;
  91.         str++;
  92.     }
  93.     if (ccase[*ptr] == ccase[*str]) {
  94.         ip = ptr;
  95.         return(1);
  96.     }
  97. #endif
  98.  
  99.     if (!*str)
  100.         if (any(*ptr," \t\n,];")) {
  101.             ip = ptr;
  102.             return(1);
  103.         }
  104.     return(0);
  105. }
  106.  
  107. /*
  108.  *      any --- does str contain c?
  109.  */
  110. int
  111. any(c,str)
  112. char    c, *str;
  113. {
  114.     while (*str)
  115.         if(*str++ == c)
  116.             return(1);
  117.     return(0);
  118. }
  119.  
  120. struct adsym    xy[] = {    /* x or y registers */
  121.     "x",    S_IX,
  122.     "y",    S_IY,
  123.     "",    0x00
  124. };
  125.